# coding:utf-8
import itertools

from django.shortcuts import render
import pymysql
from django.http import JsonResponse,FileResponse
from django.shortcuts import HttpResponse, render
import json
import numpy
import copy
import random
from itertools import product

from backend.jx3 import Damage
import os
import pymysql
from backend.db_set import db
db_data = db
def db_login():
    try:
        db = pymysql.connect(db_data['server'], db_data['user_name'], db_data['pwd'], "jx3", charset='utf8')
    except Exception as e:
        os.system('reboot')
    return db


def read(min,max):
    db = db_login()
    cursor = db.cursor()
    # print(sql)
    sql = "select * from jinengxulie where id >{0} and id <{1}".format(min,max)
    cursor.execute(sql)
    res = cursor.fetchall()
    cursor.close()
    db.close()
    return res


def luru(lst):
    db = db_login()
    cursor = db.cursor()
    # print(sql)
    sql = "update jinengxulie set dps= %s where id = %s"
    cursor.executemany(sql,lst)
    db.commit()
    cursor.close()
    db.close()




    # print(res)

res = {'jinengxulie': [], 'jinengxulie_xunhuan': ['苍棘缚地', '钩吻断肠', '紫叶沉疴', '沾衣未妨', '川乌射罔', '商陆缀寒', '银光照雪', '商陆缀寒', '商陆缀寒', '商陆缀寒', '钩吻断肠', '商陆缀寒', '川乌射罔', '含锋破月', '银光照雪', '飞叶满襟', '商陆缀寒'], 'yaoxing': 2, 'zengyifugai': {'meihuadun': 100, 'hongfa': 50, 'hanxiaoqianjun': 50, 'chaoshengyan': 5.4, 'fenlan': 40, 'shukuang': 100, 'xiaoshen': 40, 'zhenfen': 40, 'fenzhong': False}, 'jiayuancai': '1', 'jiayuanjiu': '1', 'fuzhuyaopin': '1', 'zengqiangyaopin': '1', 'fuzhushipin': '1', 'zengqiangshipin': '1', 'wuqimoshi': '1', 'jierishiwu': '1', 'ping': 2, 'shangku': '1', 'miji_shang': ['伤害+3%', '伤害+2%', '会心+4%', '会心+3%'], 'miji_gou': ['伤害+3%', '伤害+2%', '会心+4%', '会心+3%'], 'miji_xi': ['伤害+3%', '伤害+2%', '会心+4%', '会心+3%'], 'miji_qie': ['调息时间-2s', '调息时间-1s', '伤害+3%', '伤害+2%'], 'miji_yin': ['伤害+3%', '伤害+2%', '会心+5%', '会心+4%'], 'jichugongji': '13168', 'gengu': '3468', 'jiasu': '441', 'huixin': '17.09', 'huixiao': '176.66', 'pofang': '54.1', 'wushuang': '56.33', 'pozhao': '208', 'jhxj': '1', 'qixue_1': '3', 'qixue_2': '1', 'qixue_3': '2', 'qixue_4': '1', 'qixue_5': '2', 'qixue_6': '1', 'qixue_7': '1', 'qixue_8': '1', 'qixue_9': '2', 'qixue_10': '1', 'qixue_11': '1', 'qixue_12': '2', 'zhenyan': '1', 'buff': ['套装+技能伤害', '套装+双会'], 'med': [], 'target': '5'}
res['jinengxulie'] = ["千枝绽蕊"]
res['jinengxulie_xunhuan'] = []
res['yaoxing'] = 0
result = read(0,1000000)
liss = []
for i in result:
    res_yaoxing = copy.copy(res)
    res_yaoxing['yaoxing'] = int(i[2])
    res_yaoxing['jinengxulie_xunhuan'] = eval(i[3])
    dps_yaoxing = Damage(res_yaoxing).start()["data"]["dps"]
    print(dps_yaoxing, i[0])
    liss.append([dps_yaoxing, i[0]])
    if len(liss) >= 1000:
        luru(liss)
        liss = []
# print(liss)
# print(dps_yaoxing,m,a)




